package simulator;

import java.util.concurrent.ConcurrentLinkedQueue;
import core.*;

public class Analyzer extends Thread{
	
	public ConcurrentLinkedQueue<Message> msg_q = new ConcurrentLinkedQueue<Message>();
	public boolean running = true;
	
	public void run(){
		while( running ){
			// run once every sec
			try{
				sleep( 1000 );
			}catch( InterruptedException e ){
				e.printStackTrace();
			}
			
			// msg
			Message incoming_msg = msg_q.poll();
			if( incoming_msg != null ){
				// check if it's a result Worklet
				if( incoming_msg.get_attachment() != null && incoming_msg.get_attachment() instanceof Worklet ){
					
					Worklet result = ( Worklet )incoming_msg.get_attachment();
					Resource res = new Resource();
					res.set_filename( result.get_name() );
					res.set_image( result.get_image() );
					
					// display
					System.out.println( "let me see" );
					
					res.view();
				}
			}
		}//end-of-while()
	}//end-of-run()
}//end-of-class
